package com.wu.server.dao;


import com.wu.server.entity.Shop;
import com.wu.server.entity.Tag;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface NewTagRepository extends JpaRepository<Tag, Long> {
    @Query(value = "select * from jd_shop.tag where " +
            "(jd_shop.tag.id = ?1 or ?1 is null) and" +
            "(jd_shop.tag.tag_name like ?2 or ?2 is null) and" +
            "(jd_shop.tag.tag_summary between ?3 and ?4 or ?3 is null or ?4 is null)"
            , nativeQuery = true)
    Page<Tag> findAllBy(String id, String tagName, String summary1, String summary2, Pageable pageable);

    // 删除商品
    @Transactional
    @Modifying
    @Query(value = "delete from jd_shop.tag where id = ?1", nativeQuery = true)
    void deleteTagById(int id);
}
